﻿<?php $directory_resources = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));?>
<link rel="stylesheet" href="<?=$directory_resources?>colorpicker/css/colorpicker.css" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="<?=$directory_resources?>colorpicker/js/colorpicker.js"></script>
<script type="text/javascript" src="<?=$directory_resources?>colorpicker/js/eye.js"></script>
<script type="text/javascript" src="<?=$directory_resources?>colorpicker/js/utils.js"></script>
<script type="text/javascript">
	var aff_code = '';
	$(document).ready(function(){
		aff_code = $('#gahb_oh_api_key');
		$('#gahb_border_color').keyup(function(){
			$('#gahb_colorSelector1 div').css('backgroundColor', '#' + $(this).val());
		})
		$('#gahb_background_color').keyup(function(){
			$('#gahb_colorSelector2 div').css('backgroundColor', '#' + $(this).val());
		})
		$('#gahb_link_color').keyup(function(){
			$('#gahb_colorSelector3 div').css('backgroundColor', '#' + $(this).val());
		})
		$('#gahb_text_color').keyup(function(){
			$('#gahb_colorSelector4 div').css('backgroundColor', '#' + $(this).val());
		})
		$('#gahb_url_color').keyup(function(){
			$('#gahb_colorSelector5 div').css('backgroundColor', '#' + $(this).val());
		})
		$('#gahb_colorSelector5').ColorPicker({
			color: '#<?=$values->gahb_url_color?>',
			onShow: function (colpkr) {
				$(colpkr).fadeIn(500);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(500);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#gahb_colorSelector5 div').css('backgroundColor', '#' + hex);
				$('#gahb_url_color').val(hex);
			},
			onSubmit: function(hsb, hex, rgb, el) {
				$(el).ColorPickerHide();
			}
		});
		$('#gahb_colorSelector4').ColorPicker({
			color: '#<?=$values->gahb_text_color?>',
			onShow: function (colpkr) {
				$(colpkr).fadeIn(500);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(500);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#gahb_colorSelector4 div').css('backgroundColor', '#' + hex);
				$('#gahb_text_color').val(hex);
			},
			onSubmit: function(hsb, hex, rgb, el) {
				$(el).ColorPickerHide();
			}
		});
		$('#gahb_colorSelector3').ColorPicker({
			color: '#<?=$values->gahb_link_color?>',
			onShow: function (colpkr) {
				$(colpkr).fadeIn(500);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(500);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#gahb_colorSelector3 div').css('backgroundColor', '#' + hex);
				$('#gahb_link_color').val(hex);
			},
			onSubmit: function(hsb, hex, rgb, el) {
				$(el).ColorPickerHide();
			}
		});
		$('#gahb_colorSelector2').ColorPicker({
			color: '#<?=$values->gahb_background_color?>',
			onShow: function (colpkr) {
				$(colpkr).fadeIn(500);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(500);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#gahb_colorSelector2 div').css('backgroundColor', '#' + hex);
				$('#gahb_background_color').val(hex);
			},
			onSubmit: function(hsb, hex, rgb, el) {
				$(el).ColorPickerHide();
			}
		});
		$('#gahb_colorSelector1').ColorPicker({
			color: '#<?=$values->gahb_border_color?>',
			onShow: function (colpkr) {
				$(colpkr).fadeIn(500);
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(500);
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				$('#gahb_colorSelector1 div').css('backgroundColor', '#' + hex);
				$('#gahb_border_color').val(hex);
			},
			onSubmit: function(hsb, hex, rgb, el) {
				$(el).ColorPickerHide();
			}
		});
		// Calcula a porcentagem ao fazer o change
		$('#ads_percentage,#oh_percentage').change(function(){
			var ads_percentage = parseInt($('#ads_percentage').val());
			var oh_percentage = parseInt($('#oh_percentage').val());
			var dif = 0;
			if($(this).val()<=100){
				if( parseInt($(this).val()) == ads_percentage){
					dif = 100-ads_percentage;
					$('#oh_percentage').val(dif);
					$('#ads_percentage').val(100-dif);
				}
				else{
					dif = 100-oh_percentage;
					$('#ads_percentage').val(dif);
					$('#oh_percentage').val(100-dif);
				}
			}
			else{
				alert("Valor acima do permitido");
				if( parseInt($(this).val()) == ads_percentage){
					dif = 100-oh_percentage;
					$(this).val(dif);
				}
				else{
					dif = 100-ads_percentage;
					$(this).val(dif);
				}
			}
			
		});
		$('#gahb_form_save2, #gahb_form_save1, #gahb_form_save3').click(function() {
			saveAll();
		  	return false;
		});
		$('#gahb_reset_colors').click(function(){
			var colors = {};
			$.data(colors,'gahb_border_color','FFFFFF')
			$.data(colors,'gahb_background_color','FFFFFF')
			$.data(colors,'gahb_link_color','0000FF')
			$.data(colors,'gahb_text_color','000000')
			$.data(colors,'gahb_url_color','008000')
			$.each($.data(colors), function(k,v){
				$('#'+k).val(v);	
			});
			$('#gahb_border_color, #gahb_background_color, #gahb_link_color, #gahb_text_color, #gahb_url_color, ').keyup();		
		});
		$('#oh_show').click(function(){
			$(this).hide();
			$('#gahb_oh').show();
			$('#oh_hide').show();
		});
		$('#oh_hide').click(function(){
			$(this).hide();
			$('#gahb_oh').hide();
			$('#oh_show').show();
		});
		$('#ads_show').click(function(){
			$(this).hide();
			$('#gahb_ads').show();
			$('#ads_hide').show();
		});
		$('#ads_hide').click(function(){
			$(this).hide();
			$('#gahb_ads').hide();
			$('#ads_show').show();
		});
		$('.gahb_checkbox').change(function(){
			verifyCheckboxes();
		});
		verifyCheckboxes();
		$('#gahb_language').change(function(){
			$.post("/wp-content/plugins/google-adsense-and-hotel-booking/ajax.php",{
			action: 'change_language',
			gahb_language: $('#gahb_language').val()
			} ,
			function(data){
				if(data.STATUS == 'ok')
					location.href = window.location.pathname+'?page=GABH';
				else
					alert('<?=$trans['0066']?>');
			 }		
		, "json");	
		});
<?php if(!get_option('gahb_oh_api_key')){ ?>
		
		$('#gahb_oh_register_btn').click(function(){
			loader = $('#gahb_oh_register_loader');
			btn = $(this);
			btn.hide('fast',function(){
				loader.show('fast',function(){
					$.post("/wp-content/plugins/google-adsense-and-hotel-booking/proxy.php",{
						url:'http://onlinehotel.com.br/api/aff_api.php',
						function_type: 'OH_AFF_REGISTER_WP',
						email: $('#gahb_oh_email').val(),
						password: $('#gahb_oh_pass').val(),
						name: $('#gahb_oh_name').val(),
						contract_check: $('#gahb_oh_contract_check').attr('checked'),
						site:'<?=get_option(siteurl)?>'
						 } ,
						 function(data){
							$('.alert').hide();
							if(data.STATUS=='ok'){
								$.get(window.location.pathname, { page: "GABH", API_KEY: data.API_KEY, ACTION: "register_successed", NETWORK: "onlinehotel", TYPE: 'ajax', PASSWORD: $('#gahb_oh_pass').val() },
									function(data){
										location.href = window.location.pathname+'?page=GABH';
									}
								);
							}
							else{
								$.each(data.ERROR_MESSAGES,function(k,v){
									$('#gahb_oh_error_msg_'+v).show();
								});
							}
							loader.hide();
							btn.show();
						 }		
					, "json");	
				});
			});
			
		});
<?php } ?>
	});
	function saveAll(){
		//buttons and loaders
		btn = $('#gahb_form_save1, #gahb_form_save2, #gahb_form_save3');
		loader = $('#gahb_form_save1_loader, #gahb_form_save2_loader, #gahb_form_save3_loader');
		btn.hide();
		loader.show();
		
		//General Settings OH
		$.post("/wp-content/plugins/google-adsense-and-hotel-booking/ajax.php",{
			action: 'save_gahb_oh_general_settings',
			gahb_language: $('#gahb_language').val(),
			gahb_oh_paypal_account: $('#gahb_oh_paypal_account').val()
			} ,
			function(data){
				if(data.STATUS != 'ok'){
					if(data.ERROR_MESSAGE=='wrong_api_key')
						alert('<?=$trans['0064']?>');
					else if(data.ERROR_MESSAGE=='cant_update_paypal')
						alert('<?=$trans['0065']?>');
					else
						alert('<?=$trans['0066']?>');
				}
				btn.show();
				loader.hide();
			 }		
		, "json");
		
		//General Settings Adsense
		$.post("/wp-content/plugins/google-adsense-and-hotel-booking/ajax.php",{
			action: 'save_gahb_ads_general_settings',
			gahb_ads_id: $('#gahb_ads_id').val(),
			gahb_ads_chanel: $('#gahb_ads_chanel').val()
			} ,
			function(data){
				if(data.STATUS != 'ok'){
					if(data.ERROR_MESSAGE=='wrong_api_key')
						alert('<?=$trans['0064']?>');
					else
						alert('<?=$trans['0066']?>');
				}
				btn.show();
				loader.hide();
			 }		
		, "json");
		
		
		//Print Settings
		values_s = $('#gahb_form_print_settings').serialize();
		$.post("/wp-content/plugins/google-adsense-and-hotel-booking/ajax.php",{
			action: 'save_gahb_print_settings',
			values: values_s
			} ,
			function(data){
				if(data.STATUS != 'ok'){
					alert('<?=$trans['0066']?>');
				}
			 }		
		, "json");
		
	}
	function selectCityHotelList(type,name,vlink,id){
		if(type=='gahb_oh_add_city')	{
			$('#gahb_oh_add_cp_city_name_selected').val(name);	
			$('#gahb_oh_add_cp_city_link_selected').val(vlink);	
			$('#gahb_oh_add_cp_city_id_selected').val(id);	
			$('#gahb_oh_add_city_selected_name').html('<a href="'+vlink+'">'+name+'</a>');
			$('#gahb_oh_add_cp_tr_city').hide();
			$('#gahb_oh_add_city_selected_name_edit').show();
		}
		else if(type=='gahb_oh_add_hotel')	{
			$('#gahb_oh_add_cp_hotel_name_selected').val(name);	
			$('#gahb_oh_add_cp_hotel_link_selected').val(vlink);	
			$('#gahb_oh_add_cp_hotel_id_selected').val(id);	
			$('#gahb_oh_add_hotel_selected_name').html('<a href="'+vlink+'">'+name+'</a>');
			$('#gahb_oh_add_cp_tr_hotel').hide();
			$('#gahb_oh_add_hotel_selected_name_edit').show();
		}
		else if(type=='gahb_oh_edit_city')	{
			$('#gahb_oh_edit_cp_city_name_selected').val(name);	
			$('#gahb_oh_edit_cp_city_link_selected').val(vlink);	
			$('#gahb_oh_edit_cp_city_id_selected').val(id);	
			$('#gahb_oh_edit_city_selected_name').html('<a href="'+vlink+'">'+name+'</a>');
			$('#gahb_oh_edit_cp_tr_city').hide();
			$('#gahb_oh_edit_city_selected_name_edit').show();
		}
		else if(type=='gahb_oh_edit_hotel')	{
			$('#gahb_oh_edit_cp_hotel_name_selected').val(name);	
			$('#gahb_oh_edit_cp_hotel_link_selected').val(vlink);	
			$('#gahb_oh_edit_cp_hotel_id_selected').val(id);	
			$('#gahb_oh_edit_hotel_selected_name').html('<a href="'+vlink+'">'+name+'</a>');
			$('#gahb_oh_edit_cp_tr_hotel').hide();
			$('#gahb_oh_edit_hotel_selected_name_edit').show();
		}
	}
	function resetAddChange(){
		$('#gahb_oh_add_cp_tr_city, #gahb_oh_add_cp_tr_hotel').hide();
		//city
		$('#gahb_oh_add_cp_city_name_selected').val('');	//input
		$('#gahb_oh_add_cp_city_link_selected').val('');	//input
		$('#gahb_oh_add_city_selected_name').html('');		//span
		$('#gahb_oh_add_city_selected_name_edit').hide();	//btn alterar
		$('#gahb_oh_add_city_selected_name_holder').hide();	//city name holder
		$('#gahb_oh_add_city_list').hide();					//city result list
		//hotel
		$('#gahb_oh_add_cp_hotel_name_selected').val('');	//input
		$('#gahb_oh_add_cp_hotel_link_selected').val('');	//input
		$('#gahb_oh_add_hotel_selected_name').html('');		//span
		$('#gahb_oh_add_hotel_selected_name_edit').hide();	//btn alterar
		$('#gahb_oh_add_hotel_selected_name_holder').hide();	//city name holder
		$('#gahb_oh_add_hotel_list').hide();					//city result $('#list')
	}
	function resetEditChange(){
		$('#gahb_oh_edit_cp_tr_city, #gahb_oh_edit_cp_tr_hotel').hide();
		$('#gahb_oh_edit_city_selected_name_holder, #gahb_oh_edit_hotel_selected_name_holder').hide();
		$('#gahb_oh_edit_cp_target').val('all');
		$('#gahb_oh_edit_cp_id').val('');
		$('#gahb_oh_edit_cp_name').val('');
		//city
		$('#gahb_oh_edit_cp_tr_city').hide();
		$('#gahb_oh_edit_city_selected_name_edit').show();
		$('#gahb_oh_edit_city_selected_name_holder').hide();
		$('#gahb_oh_edit_city_selected_name').html('');
		$('#gahb_oh_edit_cp_city_name_selected').val('');
		$('#gahb_oh_edit_cp_city_link_selected').val('');
		$('#gahb_oh_edit_cp_city_id_selected').val('');
	}
	function resetSelectCityHotel(){
		//city
		$('#gahb_oh_edit_city_selected_name_holder').hide();
		$('#gahb_oh_edit_city_selected_name').html('');
		$('#gahb_oh_edit_cp_city_name_selected').val('');
		$('#gahb_oh_edit_cp_city_link_selected').val('');
		$('#gahb_oh_edit_cp_city_id_selected').val('');
		//hotel
		$('#gahb_oh_edit_hotel_selected_name_holder').hide();
		$('#gahb_oh_edit_hotel_selected_name').html('');
		$('#gahb_oh_edit_cp_hotel_name_selected').val('');
		$('#gahb_oh_edit_cp_hotel_link_selected').val('');
		$('#gahb_oh_edit_cp_hotel_id_selected').val('');
	}
	function editForm(id, name, target, whereId, whereName, whereLink){
		resetEditChange();
		$('#gahb_oh_cp_list').hide();
		$('#gahb_oh_edit_cp_form').show();
		$('#gahb_oh_edit_cp_id').val(id);
		$('#gahb_oh_edit_cp_name').val(name);
		$('#gahb_oh_edit_cp_target').val(target);
		if(target=='city'){
			$('#gahb_oh_edit_city_selected_name_holder').show();
			$('#gahb_oh_edit_city_selected_name').html(whereName);
			$('#gahb_oh_edit_cp_city_name_selected').val(whereName);
			$('#gahb_oh_edit_cp_city_link_selected').val(whereLink);
			$('#gahb_oh_edit_cp_city_id_selected').val(whereId);
		}
		else if (target == 'hotel'){
			$('#gahb_oh_edit_hotel_selected_name_holder').show();
			$('#gahb_oh_edit_hotel_selected_name').html(whereName);
			$('#gahb_oh_edit_cp_hotel_name_selected').val(whereName);
			$('#gahb_oh_edit_cp_hotel_link_selected').val(whereLink);
			$('#gahb_oh_edit_cp_hotel_id_selected').val(whereId);
			$('#gahb_oh_edit_cp_tr_hotel').val(whereId);
		}
	}
	function verifyCheckboxes(){
		flag=0;
		$(".gahb_checkbox").each(function(){
			temp = $(this).attr('checked');
			if	(temp==true)
				flag=1;
		});
		if (flag==0)
			$('#gahb_label_ai_468_60').attr('checked', 'true');
	}	
</script>
